<?php
    class SmskuteController extends CpController
    {
        public function init(){
            $url = new Url();
            $this->breadcrumbs[] = array('name'=>'QT SMS Kute','link'=>$url->createUrl("sms/index"),'class'=>'');
        }
        
        public function actionIndex(){
            
            $row_per_page = 20; 
            $this->breadcrumbs[] = array('name'=>'DS SMS Kute','link'=>'#','class'=>'active');
            $from_date = isset($_GET["from_date"]) ? trim($_GET["from_date"]):"";
            $to_date = isset($_GET["to_date"]) ? trim($_GET["to_date"]):"";
            $keyword = isset($_GET["keyword"]) ? trim($_GET["keyword"]):"";
            $status = isset($_GET["status"]) ? intval($_GET["status"]):2;
            $price = isset($_GET["dauso"]) ? intval($_GET["dauso"]):2;
            $page = isset($_GET["page"]) ? intval($_GET["page"]):1;
            list($max_page,$count,$data) = ASmsKute::getDataSearch($from_date,$to_date,$keyword,$status,$price,$page,$row_per_page);
            
            $this->render(
                "index"
                , array(
                    "max_page"=>$max_page
                    , "count"=>$count
                    , "data"=>$data
                    , "from_date"=>$from_date
                    , "to_date"=>$to_date
                    , "keyword"=>$keyword
                    , "price"=>$price
                    , "status"=>$status
                    , "page"=>$page
                )
            );
        }
        
        public function actionSaveRow(){
            $id = isset($_POST["id"]) ? intval($_POST["id"]):0;   
            $status = isset($_POST["status"]) ? intval($_POST["status"]):0;
            if($id >0){
                $data_old = ASmsKute::getDataById($id);
                $data = array(
                "status"=>array("value"=>$status,"type"=>1),
                "id"=>array("value"=>$id,"type"=>1),
                );
                $table = "c_sms_kute";
                $result = CommonDB::updateRow($table,$data,array("id"));
                if($result >0){
                    $act = 2;
                    $obj = 25;
                    $content = LogConfig::$action[$act].' '.LogConfig::$object[$obj].': {id: '.$id.',name: '.$data_old["title"].',status: '.$data_old["status"].'} thành ';
                    $content .= ' {id: '.$id.',name: '.$data_old["title"].',status: '.$status.'}';
                    $result = AAdminLog::insertAdminLog($act,$obj,$content);
                    echo 1;exit;
                }else{
                    echo "Chưa thay đổi dữ liệu";exit;
                }
            }
        }
        
        public function actionDeleteRow(){
            $id = isset($_POST["id"]) ? intval($_POST["id"]):0;
            if($id >0){
                $data_old = ASmsKute::getDataById($id);
                $table = "c_sms_kute";
                $result = CommonDB::deleteRow($table,array("id"=>$id));
                if($result >0){
                    $act = 3;
                    $obj = 25;
                    $content = LogConfig::$action[$act].' '.LogConfig::$object[$obj].': {id: '.$id.',name: '.$data_old["title"].'}';
                    $result = AAdminLog::insertAdminLog($act,$obj,$content);
                    echo 1;exit;
                }else{
                    echo "Chưa thay đổi dữ liệu";exit;
                }
            }
        }
    }
?>
